package com.heatingcharge.controller.charge;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.ChargePlanDTO;
import com.heatingcharge.param.ChargePlanParam;
import com.heatingcharge.param.ChargePlanParam;
import com.heatingcharge.service.charge.IChargePlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 收费计划 前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-12-27
 */
@RestController
@RequestMapping("/charge-plan")
public class ChargePlanController {
    @Autowired
    IChargePlanService chargePlanService;

    @ApiOperation(value = "分页获取收费计划信息",notes = "分页获取收费计划信息")
    @GetMapping()
    public R getChargePlan(Page page, ChargePlanParam chargePlanParam){
        IPage<ChargePlanDTO> chargePlanDTOIPage=chargePlanService.getChargePlans(page,chargePlanParam);
        return R.ok(chargePlanDTOIPage);
    }

    @ApiOperation(value = "新增小区",notes = "新增小区")
    @PostMapping
    public R saveChargePlan(@RequestBody ChargePlanParam chargePlanParam){
        if (chargePlanService.save(chargePlanParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新小区",notes = "更新小区")
    @PutMapping
    public R updateChargePlan(@RequestBody ChargePlanParam chargePlanParam){
        if (chargePlanService.update(chargePlanParam)){
            return R.ok();
        }
        return R.error();
    }
}

